<template>
	<view>
		<u-tabs :list="list1" lineWidth="45" :scrollable="false" lineColor="#ac9281"></u-tabs>
		<!-- {{orders}} -->
		<order-list-vue :orders='orders'></order-list-vue>
		<!-- 	<orderList></orderList> -->
		<!--  <view v-if="currentTab === 0">
    
      <orderList :orders="orders" @deleteOrder="deleteOrder"></orderList>
    </view> -->
		<!-- 其他标签页内容 -->
	</view>
</template>

<script>
	//从父组件传值到子组件
	import orderListVue from './orderList/orderList.vue';
	export default {
		data() {
			return {
				current: 0, // 当前选中的标签索引
				list1: [{
						name: '待支付',
						key: 0
					},
					{
						name: '已支付',
						key: 1
					},
					{
						name: '全部订单',
						key: 2
					},
				],
				orders: [], // 存储订单数据
				currentTab: 0, // 当前显示的订单类型
			};
		},
		components: {
			orderListVue
		},
		onLoad() {
			this.userId = uni.getStorageSync('userId'); // 获取用户ID
			this.fetchOrders();
		},
		methods: {
			// onTabChange(index) {
			//   this.currentTab = index;
			//   this.fetchOrders(index);
			// },
			fetchOrders() {
			  const url = `http://localhost:8083/orders/ordersByUserId/${this.userId}`; // 假设后端支持通过查询参数传递订单类型
			  uni.request({
			    url: url,
			    success: (res) => {
			      // if (res.statusCode === 200) {
			      //   this.orders = res.data;
			      // }
			this.orders = res.data;
			    },
			    fail: (err) => {
			      console.error(err);
			    },
			  });
			},
			deleteOrder(orderId) {
			  uni.request({
			    url: `http://localhost:8083/orders/delete/${this.userId}`,
			    method: 'GET',
			    success: (res) => {
					console.log('删除订单成功')
			      // if (res.statusCode === 200) {
			      //   // 删除订单成功，从列表中移除
			        this.orders = this.orders.filter(order => order.id !== orderId);
			      // } else {
			      //   console.error('删除订单失败', res);
			      // }
			    },
			    fail: (err) => {
			      console.error(err);
			    },
			  });
			},
		},
	};
</script>

<style>
	/* 样式 */
</style>